package cn.jiyun.provider.controller;

import cn.jiyun.provider.common.R;
import cn.jiyun.provider.pojo.Dept;
import cn.jiyun.provider.pojo.Emp;
import cn.jiyun.provider.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;
    @RequestMapping("/findEmpAll")
    public List<Emp> findEmpAll(){
        return empService.getEmpAll();
    }
    @RequestMapping("/findPage")
    public R findPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "3") Integer pageSize,String name){
       return empService.findPage(page, pageSize,name);
    }
    @RequestMapping("/add")
    public R add(@RequestBody Emp emp){
        empService.add(emp);
        return R.success("添加成功");
    }
    @RequestMapping("/findById")
    public R findById(Integer id){
        Emp emp=empService.findById(id);
        return R.success(emp);
    }
    @RequestMapping("/getDept")
    public List<Dept> getDept(){
       return empService.getDept();
    }
    @RequestMapping("/edit")
    public R edit(@RequestBody Emp emp){
        empService.edit(emp);
        return R.success("编辑成功");
    }
    @RequestMapping("/delete")
    public R delete(Integer id){
        empService.delete(id);
        return R.success("删除成功");
    }
    @RequestMapping("/exportExcel")
    public R exportExcel(HttpServletResponse response){
        empService.exportExcel(response);
        return R.success("导出成功");
    }

}
